//
//  WeekDayView.m
//  MiaoTu
//
//  Created by dllo on 16/9/10.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "WeekDayView.h"

@interface WeekDayView ()
@property (nonatomic, strong) NSArray *weekdayArray;
@property (nonatomic, strong) UILabel *monthLabel;
@property (nonatomic, strong) UILabel *label0;
@property (nonatomic, strong) UILabel *label1;
@property (nonatomic, strong) UILabel *label2;
@property (nonatomic, strong) UILabel *label3;
@property (nonatomic, strong) UILabel *label4;
@property (nonatomic, strong) UILabel *label5;
@property (nonatomic, strong) UILabel *label6;
@end

@implementation WeekDayView

- (void)setMonthString:(NSString *)monthString {
    _monthString = monthString;
    _monthLabel.text = _monthString;
}

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        _weekdayArray = @[@"日", @"一", @"二", @"三", @"四", @"五", @"六"];
        _monthLabel = [UILabel new];
        [self addSubview:_monthLabel];
        _label0 = [UILabel new];
        [self addSubview:_label0];
        _label1 = [UILabel new];
        [self addSubview:_label1];
        _label2 = [UILabel new];
        [self addSubview:_label2];
        _label3 = [UILabel new];
        [self addSubview:_label3];
        _label4 = [UILabel new];
        [self addSubview:_label4];
        _label5 = [UILabel new];
        [self addSubview:_label5];
        _label6 = [UILabel new];
        [self addSubview:_label6];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat width = self.frame.size.width / _weekdayArray.count;
    CGFloat height = self.frame.size.height;
    
    _monthLabel.frame = CGRectMake(0, 0, self.bounds.size.width, height / 2);
    _monthLabel.textAlignment = NSTextAlignmentCenter;
    
    NSArray *labelArray = @[_label0, _label1, _label2, _label3, _label4, _label5, _label6];
    
    for (int i = 0; i < _weekdayArray.count; i++) {
        UILabel *label = labelArray[i];
        label.frame = CGRectMake(width * i, height / 2, width, height / 2);
        label.text = _weekdayArray[i];
        label.textAlignment = NSTextAlignmentCenter;
        if (i == 0 || i == 6) {
            label.textColor = [UIColor orangeColor];
        }
    }
}


@end
